﻿using System;
using XamlingCore.Infrastructure.Dialog;

namespace XamlingCore.WP.Infrastructure.Exceptions
{
    public class ExceptionManager
    {
        private IExceptionTranslator translator;

        public event EventHandler<UserFriendlyExceptionEventArgs> UserFriendlyExceptionRaised;

        public ExceptionManager(IExceptionTranslator translator)
        {
            this.translator = translator;
        }
        public void LogException(Exception ex, DialogMessageButtons buttons, bool showDialog)
        {
            LogException(ex, buttons, showDialog, null);
        }

        public void LogException(Exception ex, DialogMessageButtons buttons, bool showDialog, Action<bool> resultCallback)
        {
            //TODO: Log the exception somewhere
            if (showDialog)
            {
                if (UserFriendlyExceptionRaised != null)
                {
                    UserFriendlyExceptionRaised(this, new UserFriendlyExceptionEventArgs(translator.TranslateException(ex), buttons, resultCallback));
                }
            }
        }
    }
}
